<template>
	<view class="page">
		<view class="searchBox">
			<view class="inputBox">
				<view class="inputRow" style=""  v-if="isTeacher==1">
					<view class="label">
						{{language.attendanceRecord.label1}}:
					</view>
					<view class="val" >
						<u-input v-model="params.personCode" :placeholder="language.attendanceRecord.tip1"></u-input>
					</view>
				</view>
				<view class="inputRow" style=""  v-if="isTeacher==1" >
					<view class="label">
						{{language.attendanceRecord.label2}}:
					</view>
					<view class="val" >
						<u-input v-model="params.personName" :placeholder="language.attendanceRecord.tip1"></u-input>
					</view>
				</view>
				<view class="inputRow">
					<view class="label">
						{{language.attendanceRecord.label3}}:
					</view>
					<view :class="params.accessDateBegin ? 'val' : 'emty'" @click="accessDateBeginShow=true">
						{{params.accessDateBegin ? params.accessDateBegin : language.attendanceRecord.tip2 }}
					</view>
				</view>
				<view class="inputRow">
						<view class="label">
							{{language.attendanceRecord.label4}}:
						</view>
						<view :class="params.accessDateEnd ? 'val' : 'emty'" @click="accessDateEndShow=true">
							{{params.accessDateEnd ? params.accessDateEnd : language.attendanceRecord.tip2 }}
						</view>
				</view>
			</view>
			<view class="btnBox">
				<view class="btn"  @click="goSearch">
					{{language.attendanceRecord.search}}
				</view>
			</view>
			
		</view>
		
			<scrollYBox styleText="height: calc( 100vh - 300rpx );" @scrolltolower="scrolltolower" :list="list">
						<template>
							<view style="padding-bottom: 50rpx;">
								<view class="boxItem" v-for="(item,index) in list" :key="index">
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{language.attendanceRecord.label5}}
											</view>
											<view class="val">
												{{item.personDepartmentName | emptyStr }}
											</view>
										</view>
										<view class="item ">
											<view class="label">
												{{language.attendanceRecord.label1}}
											</view>
											<view class="val">
												{{item.personCode | emptyStr }}
											</view>
										</view>
										
									</view>
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{language.attendanceRecord.label2}}
											</view>
											<view class="val">
												{{item.personName | emptyStr }}
											</view>
										</view>
										<view class="item ">
											<view class="label">
												{{language.attendanceRecord.label6}}
											</view>
											<view class="val">
												{{item.accessDate | emptyStr }}
											</view>
										</view>
									</view>
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{language.attendanceRecord.label7}}
											</view>
											<view class="val">
												{{item.deviceName | emptyStr }}
											</view>
										</view>
										<view class="item ">
											<view class="label">
												{{language.attendanceRecord.label8}}
											</view>
											<view class="val">
												{{item.accessMethod_dictText | emptyStr }}
											</view>
										</view>
										<!-- <view class="item ">
											<view class="btn" @click="handleDetail(item)">
												详情
											</view>
										</view> -->
									</view>
								</view>
							</view>
						</template>
					</scrollYBox>
	
		<u-datetime-picker
		    :show="accessDateBeginShow" ref="datetimePicker" v-model="accessDateBegin" 
		    mode="date"  @cancel="accessDateBeginShow=false" @confirm="accessDateBeginConfirm"
		       ></u-datetime-picker>
		<u-datetime-picker
			:show="accessDateEndShow" ref="datetimePicker" v-model="accessDateEnd" 
			mode="date"  @cancel="accessDateEndShow=false" @confirm="accessDateEndConfirm"
	       ></u-datetime-picker>
	</view>
</template>

<script>
	import {dormDeviceAccessRecordListApi,enterRoomRecordApi} from '@/common/api/commonApi/dormApi.js'
	export default {
		data() {
			return {
				list:[],
				params:{
					personName: '',
					personCode: '',
					pageNo : 1,
					pageSize : 10,
					accessDateBegin : '',
					accessDateEnd : '',
					isVisiter:0,
				},
				accessDateBegin: Number(new Date()),
				accessDateEnd: Number(new Date()),
				accessDateBeginShow : false,
				accessDateEndShow : false,
				total : 0,
				selectLabel : '',
				isTeacher: uni.getStorageSync('isTeacher'),
				selectInfoAccount: uni.getStorageSync('selectInfoAccount'),
			}
		},
		components:{
		},
		methods: {
			handleDetail(item){
				this.goPage('/pages/componentsC/safe/accessRecordDetail',{id:1})
			},
			scrolltolower(){
				if(this.total == this.list.length){
					return this.setMessage('没有更多了')
				}
				this.params.pageNo ++
				this.getList()
			},
			goSearch(){
				this.params.pageNo = 1 
				this.getList()
			},
			accessDateBeginConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.accessDateBegin = date
				console.log(this.params.accessDateBegin);
				this.accessDateBeginShow = false
			},
			accessDateEndConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.accessDateEnd = date
				this.accessDateEndShow = false
			},
			getList(){
				let params = this.params
				if(this.isTeacher==2){
					params.personId = this.selectInfoAccount.id
					return enterRoomRecordApi(params).then(res=>{
						if(params.pageNo==1) this.list = []
						this.list = this.list.concat(res.result.records)
						this.total = res.result.total
					})
				}
				
				dormDeviceAccessRecordListApi(params).then(res=>{
					if(params.pageNo==1) this.list = []
					this.list = this.list.concat(res.result.records)
					this.total = res.result.total
				})
			},
			goSearch(){
				this.params.pageNo = 1
				this.getList()
			},
			
			
		},
		onLoad() {
			this.setPageTitle(this.language.attendanceRecord.title)
			this.getList()
			if(this.isTeacher==2){
				this.setPageTitle('归寝记录')
			}else{
				
			}
		},
		onShow() {
		},
	}
</script>

<style lang="scss" scoped>
.page{
	background-color: #f1f1f1;
	// height: 100vh;
	.searchBox{
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 0 20rpx;
		border-bottom: 1px solid #f1f1f1;
		margin: 20rpx;
		border-radius: 8rpx;
		box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.16);
		.inputBox{
			flex: 1;
			padding-right: 30rpx;
			.inputRow{
				height: 80rpx;
				display: flex;
				align-items: center;
				font-size: 32rpx;
				padding-left: 20rpx;
				.label{
					color: #191919;
					margin-right: 30rpx;
				}
			}
			.input{
				
			}
			.emty{
				color: #c0c4cc;
			}
			.val{
				
			}
		}
		.btnBox{
			display: flex;
			flex-direction: column;
			padding: 10rpx 0;
			.reset{
				margin-top: 20rpx;
				border: 1px solid #f1f1f1;
				background: #fff !important;
				color: #353535 !important;
			}
			.btn{
				padding: 0 30rpx;
				// width: 110rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #1890ff;
				border-radius: 8rpx;
				color: #fff;
			}
		}
	}
	
	.boxItem{
			background-color: #fff;
			margin: 20rpx;
			border-radius: 8rpx;
			padding: 10rpx;
			box-shadow: 0px 0px 20rpx 0px rgba(102,102,102,0.15);
			.row{
				margin: 10rpx;
				display: flex;
				.item{
					width: 50%;
					// flex: 1;
				}
				.label{
					color: #969696;
				}
				.val{
					color: #353535;
					font-size: 32rpx;
				}
				.btn{
						padding: 0 30rpx;
						width: 120rpx;
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background: #1890ff;
						border-radius: 8rpx;
						color: #fff;
				}
			}
		}
		
}
</style>
